/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package wf3.gps;

import acceso.util.Escritor;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author john
 */
public class Thread_markers implements Runnable{
    
    private String color;
    private String[] sizes = {"0.05","0.10","0.12","0.13","0.14","0.15","0.16","0.17","0.18","0.19","0.20","0.25","0.30","0.40","0.42","0.44","0.46","0.48","0.50","0.52","0.54","0.56"};
    private String url_img;

    public Thread_markers(String color, String url_img) {
        this.color = color;
        this.url_img = url_img;
    }
    
    @Override
    public void run() {
        URL url = null;
        for(int i=0; i<sizes.length; i++){
            OutputStream os = null;
            InputStream is = null;
            try {
                url = new URL("http://chart.apis.google.com/chart?chst=d_map_spin&chld="+sizes[i]+"|0|"+color+"|8|_|");
                is = url.openStream();
                os = new FileOutputStream(url_img+color+"_"+sizes[i]+".png");
                byte[] b = new byte[2048];
                int length;
                while ((length = is.read(b)) != -1) {
                        os.write(b, 0, length);
                }
            } catch (Exception ex) {
                Escritor.escribe_errors("Error Thread_markers: "+ex.getMessage());
            } finally {
                try {
                    os.close();
                    is.close();
                } catch (IOException ex) {
                    Escritor.escribe_errors("Error Thread_markers: "+ex.getMessage());
                }
            }
        }
    }
    
}
